## Replication for Table 1
# In case of any questions, please email anselm.rink@gmail.com

rm(list=ls())
library(foreign)
library(fBasics)
library(psych)
library(stargazer)
setwd("")
data <- read.dta("")

## Indexes 

#Economic marginalization index -- four variables: q7_has_job q8_has_income q8_income_last_month_ln q9_chance_become_rich
data$q8_income_last_month_ln <- ifelse(data$q8_income_last_month>0,log(data$q8_income_last_month),0)
(economically_marginalized_index <- alpha(data[, c("q7_has_job", "q8_has_income", "q8_income_last_month_ln", "q9_chance_become_rich")]))
economically_marginalized_index <- economically_marginalized_index$scores
economically_marginalized_index <- max(economically_marginalized_index, na.rm=T)-economically_marginalized_index
summary(economically_marginalized_index)

#Political marginalization index -- three variables q10_plans_to_vote q11_govt_represents_interest q12_feels_on_loosing_side
(politically_marginalized_index <- alpha(data[, c("q10_plans_to_vote", "q11_govt_represents_interest", "q12_feels_on_loosing_side")]))
politically_marginalized_index <- politically_marginalized_index$scores
politically_marginalized_index <- max(politically_marginalized_index, na.rm=T)-politically_marginalized_index
summary(politically_marginalized_index)

#Troubled family relations index -- three variables: q19_rlts_mother q20_rlts_father q21_respect_friends_family
(troubled_family_index <- alpha(data[,c("q19_rlts_mother", "q20_rlts_father", "q21_respect_friends_family" )]))
troubled_family_index <- troubled_family_index$scores
summary(troubled_family_index)

#Exposure to violence -- two variables: q15_witnesses_interrel_violence q16_witnesses_viol_musl_govt
(violence_exposure_index <- alpha(data[,c("q15_witnesses_interrel_violence", "q16_witnesses_viol_musl_govt")]))
violence_exposure_index <- violence_exposure_index$scores
summary(violence_exposure_index)

#Religiosity -- two variables: q22_religion q23_frequents_house_worship
(religiosity_index <- alpha(data[,c("q22_religion", "q23_frequents_house_worship")]))
religiosity_index <- religiosity_index$scores
summary(religiosity_index)

#Destructive life events -- five variables:  q17_friend_family_died q18_lost_job q18_arrested q18_house_of_worship_raided q18_stopped_speaking_parents q18_love_problems q18_friend_left_country
(destructive_events_index <- alpha(data[,c("q17_friend_family_died", "q18_lost_job", "q18_arrested", "q18_house_of_worship_raided", "q18_stopped_speaking_parents", "q18_love_problems", "q18_friend_left_country")]))
destructive_events_index <- destructive_events_index$scores
summary(destructive_events_index)

data$economically_marginalized_index <- economically_marginalized_index
data$politically_marginalized_index <- politically_marginalized_index
data$religiosity_index <- religiosity_index
data$destructive_events_index <- destructive_events_index
data$troubled_family_index <- troubled_family_index
data$violence_exposure_index <- violence_exposure_index

## Regressions

d <- lm(q27_radicalization ~ economically_marginalized_index + politically_marginalized_index + troubled_family_index + violence_exposure_index + religiosity_index + destructive_events_index + q13_b_knows_emigrant_som_eri + respondent_muslim + respondent_male + q1_age + q5_convert + q6_married, data=data)
e <- lm(q27_radicalization ~ economically_marginalized_index + politically_marginalized_index + troubled_family_index + violence_exposure_index + religiosity_index + destructive_events_index + q13_b_knows_emigrant_som_eri + respondent_muslim + respondent_male + q1_age + q5_convert + q6_married, data=data, respondent_muslim==1)
f <- lm(q27_radicalization ~ economically_marginalized_index + politically_marginalized_index + troubled_family_index + violence_exposure_index + religiosity_index + destructive_events_index + q13_b_knows_emigrant_som_eri + respondent_muslim + respondent_male + q1_age + q5_convert + q6_married, data=data, respondent_muslim==0)

stargazer(d,e,f, star.cutoffs = c(0.05, 0.01, 0.001))
